<?php

namespace app\api\validate;

use think\Validate;

/**
 * Admin 验证器
 * Class Admin
 * @package app\admin\validate
 */
class Admin extends Validate
{
    /**
     * @var string[] 验证规则
     */
    protected $rule = [
        'username' => 'require|alphaNum|length:6,10',
        'password' => 'require|alphaDash|length:6,10',
        'login_password' => 'require|alphaNum|length:32',
        'login_ip' => 'ip',
        'qq_open_id' => 'require|length:32',
        'qq_app_id' => 'require',
        'nickname' => 'require',
        'captcha' => 'require|captcha',
        'status' => 'require|number|in:0,1',
        'role_id' => 'require|number',
        'token' => 'require',
        'id' => 'require'
    ];

    /**
     * @var string[] 验证不同过的错误提示
     */
    protected $message = [
        'username.require' => '用户名不能为空!',
        'username.alphaNum' => '用户名只能为数字或字母组合!',
        'username.length' => '用户名长度不正确!',
        'password.require' => '密码不能为空!',
        'password.alphaDash' => '密码只能为数字、字母、下划线或破折号的组合!',
        'password.length' => '密码长度不正确!',
        'login_password.require' => '密码不能为空!',
        'login_password.alphaDash' => '密码组合不合法!',
        'login_password.length' => '密码长度不正确!',
        'login_ip.ip' => '无法获取客户端请求ip!',
        'qq_open_id.require' => 'openid不能为空!',
        'qq_open_id.length' => 'openid长度不正确!',
        'qq_app_id.require' => 'appid不能为空!',
        'nickname.require' => '昵称不能为空!',
        'captcha.require' => '验证码不能为空!',
        'captcha.captcha' => '验证码错误!',
        'status.require' => '用户状态不能为空!',
        'status.number' => '用户状态不正确!',
        'status.in' => '用户状态不合法!',
        'role_id.require' => '角色不能为空!',
        'role_id.number' => '角色不正确!',
        'id.require'=>'缺少用户关键参数!'
    ];

    /**
     * @var \string[][] 验证场景
     */
    protected $scene = [
        'login' => ['username', 'login_password', 'login_ip', 'captcha'],
        'qq_login' => ['qq_open_id', 'qq_app_id', 'login_ip'],
        'add' => ['username', 'nickname', 'role_id', 'password', 'status'],
        'detail' => ['id'],
        'edit' => ['id', 'username', 'nickname', 'role_id', 'password'],
        'del' => ['id'],
        'auth' => ['token'],
        'test'=>['captcha']
    ];

}
